/**************************************************************************
*   Copyright (C) 2009 Chernov Dmitry                                     *
*   diman4ik.chernov@gmail.com                                            *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef KORNERS_GAME_ENGINE_NETWORK
#define KORNERS_GAME_ENGINE_NETWORK

#include "korners_game_engine.h"
#include "korners_protocol.h"

class KornersSocket;
class KornersServer;

class KornersGameEngineNetwork : public KornersEngine
{
    Q_OBJECT
public:

    explicit KornersGameEngineNetwork(  const QString& netName, bool server, int port, 
                                        const QString& peerIp = "localhost");

    ~KornersGameEngineNetwork();

    void makeNextMove( const QPoint& src, const QPoint& dst );

    bool canSelect( const QPoint& src ) const;
    bool canMove( QPoint src, QPoint dst ) const;

public slots:
    void messageReceived( KornersMessage mess );
    void incomingConnection();
    void onDisconnect();
    void connectionFailed();

signals:
    void opponentName( QString name );

private:
    QString m_nickName;
    QString m_peerName;
    KornersProtocol* m_curGameProto;
    KornersSocket* m_socket;
    KornersServer* m_server;
};

#endif